from apps.dbConnect.dbCurd import dbCurdD
def printCodeShengchan(print_task):
    """
    生产条码打印数据查询
    :param print_task:打印机
    :return:
    """
    sql1 = """
select top 1 id,isnull(qty,0) as qty,id,[order] from xt_printtask where status=0 and [print]=:print_task order by create_time asc
    """
    print_d ,err = dbCurdD.dbOneJson(sql1,{"print_task":print_task})
    if err!=None:
        return None,'打印任务查询失败'+err
    if print_d is None:
        return None, '没有打印任务'
    if print_d['qty'] <1:
        return None, '打印任务打印分数异常异常'

    sql2 = """
select ROW_NUMBER() OVER(ORDER BY a.CREATEDON desc) AS ROWNUMBER,b.DocNo AS MO_NO,D.NAME AS DEP_NAME,C.ID AS PRD_NO, C.NAME AS PRD_NAME,c.SPECS  as spc,a.DocNo as zy_no,FORMAT(a.CREATEDON, 'yyyy-MM-dd') as zy_dd, cast(cast(a.TransferQty as REAL) as varchar(20)) as qty,a.SrcOperation as s_gz,a.TargetOperation as x_gz,a.SrcOpDesc as s_gz_name,a.TargetOpDesc as x_gx_name
,case when isnull(a.ApproveBy,'')!='' then '已审' else '待审' end as ApproveBy,isnull(E.QTY,0) AS RK_QTY,isnull(cz_name,'') AS RK_cz_name,isnull(E.lr_name,'') AS RK_lr_name,isnull(E.bat_no,'') AS RK_bat_no,isnull(E.rem,'') AS RK_rem
from MO_OpTransferDoc a
left join mo_mo b on a.mo=b.id
LEFT JOIN CBO_ItemMaster C ON C.ID=b.ItemMaster
LEFT JOIN CBO_Department_Trl D ON D.id=B.department
LEFT JOIN xt_rkrecord E ON A.DocNo=E.ID
WHERE isnull(a.DocNo,'')!='' and B.department='1002212310027358' and B.MODocType in('1002301170062643','1002303070028447','1002303160032995'/*机加生产订单*/,'1002212240136909','1002212240220566',/*压铸生产订单*/'1002212300000078','1002212310035482')
 and a.DocNo=:pk
    """

    data,err = dbCurdD.dbOneJson(sql2,{"pk":print_d['order']})
    if err!=None:
        return None,'打印数据查询失败'+err

    if data is None:
        return None, '打印单号异常没有查询单打印数据'
    data['print_task_id'] = print_d['id']
    dataList = []

    if print_d['qty']==1:
        dataList.append(data)
    for i in range(print_d['qty']):
        dataList.append(data)

    return dataList,None

def printCodeCaiwu(print_task):
    """
    固定资产条码打印数据查询
    :param print_task:打印机
    :return:
    """

    return